<template>

        <div class="left" ref="element">
            <div class="name">
                <router-link :to="userInfo? '':'/register/login'">
                      <img src="@/assets/img/touxiang.png" alt="" v-if='userInfo' />
                      <img src="@/assets/img/touxiang.png" alt="" v-else />
                    
                      <p v-if='userInfo' >{{userInfo.user_nickname}}</p>
                      <p v-else>登录/注册</p>

                      <span v-if='userInfo'>
                        {{biding_num_text}}：{{biding_num}}
                      </span>
                      <span v-else>
                        招标中：0
                      </span>
                      <span v-if='userInfo'>
                        {{enlist_num_text}}：{{enlist_num}}
                      </span>
                      <span v-else>
                         已投：0 
                      </span>

                 </router-link >
                
            </div>
            <div class="personal-menus" >
                <ul  :style="ulheight">
                    <li @click="toDidlist">
                          <p class="personal-menus1" :class="my1_class"><span>我的订单</span></p>
                    </li >
                    <li @click="toNotice">
                         <p class="personal-menus2"  :class="my2_class"><span>消息中心</span></p>
                    </li>
                    <li @click="toAuth">
                        <p class="personal-menus3"  :class="my3_class"><span>身份认证</span></p>
                    </li>
                    <li @click="toInviteman">
                        <p class="personal-menus4"  :class="my4_class"><span>成为合伙人</span></p>
                    </li>
                    <li @click="toEditpass">
                        <p class="personal-menus5"  :class="my5_class"><span>修改密码</span></p>
                    </li>
                    <li @click="toAgree">
                        <p class="personal-menus6"  :class="my6_class"><span>医竞采协议</span></p>
                    </li>
                </ul>
            </div>
        </div>


</div>

</template>

<script>
// @ is an alias to /src
import Swiper from 'swiper';

export default {
  name: 'my',
  // inject:['reload'],
  data(){
    return{
        userInfo:'',
        my1_class:'',
        my2_class:'',
        my3_class:'',
        my4_class:'',
        my5_class:'',
        my6_class:'',

        biding_num_text:'招标中',
        enlist_num_text:'已投',
        biding_num:0,
        enlist_num:0,
        ulheight:''

     }
  },
  async created(){
   
    this.userInfo = this.getUserInfo();

    switch(this.$route.path){
      case '/my/bidlist':
      this.my1_class='active';
      break;
      case '/my/notice':
      this.my2_class='active';
      break;
      case '/my/usertype':
      this.my3_class='active';
      break;
      case '/my/inviteman':
      this.my4_class='active';
      break;
      case '/my/editpass':
      this.my5_class='active';
      break;
      case '/my/agree':
      this.my6_class='active';
      break;
    }

    this.userInfo = this.getUserInfo()
       let re = await this.$axios.get('user/myInit')
       if(re.code == 200){
              this.biding_num = re.data.biding_num
              this.enlist_num = re.data.enlist_num
              this.biding_num_text = re.data.biding_num_text
              this.enlist_num_text = re.data.enlist_num_text

        }

        let height= this.$refs.element.offsetHeight
        this.ulheight = 'height:'+height+'px';
       
  },

  mounted(){

     // this.$nextTick(() => {
         //let height= this.$refs.element.offsetHeight; //100

        //获取元素样式值,element 为元素ref="element"
        //var heightCss = window.getComputedStyle(this.$refs.element).height;

        //获取元素内联样式值
        //var heightStyle =this.$refs.element.style.height; // 100px
        //this.ulheight = 'height:'+800;

        //console.log(ulheight)
    // });
            
  },
  components: {
     
  },
  methods:{
    //去标书列表
    toDidlist(){
        this.$router.push({path:'/my/bidlist'})
    },
    //去消息中心
    toNotice(){
        this.$router.push({path:'/my/notice'})
    },
    //身份认证
    async toAuth(){
       let user = await this.$axios.get('user/getUserByToken')
        if(user.code == 200){
              if(user.data.user_type ==0){
                this.$router.push({path:'/register/status'})
                 
              }else{
                 this.$router.push({path:'/my/usertype'})
               
              }
          
           }
    },
    //成为合伙人
    async toInviteman(){
    let user = await this.$axios.get('user/getUserByToken')
        if(user.code == 200){
             if(user.data.is_invite ==0){

                 let re =  this.$axios.post('user/goInvite')
                 .then(response => {
                     if(response.code == 200){
                        this.$router.push({path:'/my/inviteman'})
                      }
                 })
                     
                
              }else{
                 this.$router.push({path:'/my/inviteman'})
               
              }
          
         }
              
    },
    //修改密码
    async toEditpass(){
       let user = await this.$axios.get('user/getUserByToken')
        if(user.code == 200){
              if(user.data.user_type ==0){
                this.$router.push({path:'/register/status'})
                 
              }else{
                 this.$router.push({path:'/my/editpass'})
               
              }
          
           }

    },
    //协议
    toAgree(){
        this.$router.push({path:'/my/agree'})
    },
    
  }
}
</script>

